// imgSize.js
//  图片尺寸限制
import { MessageBox, Message } from "element-ui";
import { ERROR } from "dropzone";
export async function imgSizi(file, myWidth, myHeight) {
  try {
    await new Promise(function(resolve, reject) {
      let width = myWidth;
      let height = myHeight;
      let _URL = window.URL || window.webkitURL;
      let img = new Image();
      img.onload = function() {
        let valid = img.width == width && img.height == height;
        valid ? resolve() : reject();
      };
      img.src = _URL.createObjectURL(file);
    });
    return file;
  } catch (e) {
    Message({
      message: `上传的图片宽高必须是等于${myWidth}*${myHeight}!`,
      type: "error"
    });
    return Promise.reject();
  }
}
export function randomString(len) {
  len = len || 20;
  var $chars =
    "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678"; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
  var maxPos = $chars.length;
  var pwd = "";
  for (let i = 0; i < len; i++) {
    pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
  }
  return pwd;
}
export function ifObj(params) {
  let flag = true;
  for (var key in params) {
    if (params[key] != "0" && !params[key]) {
      return false; // 终止程序
    }
  }

  return flag;
}
export function ifObjTow(params) {
  for (let key in params) {
    if (params[key] == null) {
      throw new Error("参数不完整");
    }
  }
}
let baseUrl2 = "";
let manage2 = "";
switch (process.env.NODE_ENV) {
  case "development":
    baseUrl2 = "http://192.168.1.111"; //开发环境url`
    manage2 = "./";
    break;
  case "production":
    // baseUrl2 = "https://teacity.xgpays.com"; //生产环境url
    manage2 = "./manage";
    baseUrl2 = "http://156vlsovu6.52http.net"; //生产环境url
    break;
}
export let baseUrl = baseUrl2;
export let manage = manage2;
